package com.pgeneral.user.management.controller;

import com.pgeneral.user.management.config.ResultBean;
import com.pgeneral.user.management.entity.DepartmentInfo;
import com.pgeneral.user.management.service.impl.DepartmentInfoServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 科室的增删改查接口
 */
@Slf4j
@RestController
@RequestMapping("/departmentinfo")
public class DepartmentInfoController {

    @Autowired
    private DepartmentInfoServiceImpl departmentinfoService;

    /**
     * 添加科室信息
     *
     * @param departmentInfos
     * @return
     */
    @RequestMapping(value = "/saveInfo", method = RequestMethod.POST)
    public ResultBean insertDepartmentinfoTable(@RequestBody List<DepartmentInfo> departmentInfos) {
        log.info("调用科室save方法，方法参数为：{}",departmentInfos);
        int result = departmentinfoService.insert(departmentInfos);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 科室查询
     *
     * @param departmentinfo
     * @return
     */
    @RequestMapping(value = "/getInfo", method = RequestMethod.POST)
    public ResultBean getDepartmentinfoTable(@RequestBody DepartmentInfo departmentinfo) {
        log.info("调用科室get方法，方法参数为：{}",departmentinfo);
        List<DepartmentInfo> departmentInfos = departmentinfoService.getDepartmentinfoTable(departmentinfo);
        return ResultBean.Success(departmentInfos);

    }

    /**
     * 科室更新
     *
     * @param departmentInfos
     * @return
     */
    @RequestMapping(value = "/updateInfo", method = RequestMethod.POST)
    public ResultBean updateDepartmentinfoTable(@RequestBody List<DepartmentInfo> departmentInfos) {
        log.info("调用科室update方法，方法参数为：{}",departmentInfos);
        int result = departmentinfoService.updateDepartmentinfoTable(departmentInfos);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 科室删除
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteInfo", method = RequestMethod.POST)
    public ResultBean deleteDepartmentinfoTable(@RequestBody List<String> ids) {
        log.info("调用科室delete方法，方法参数为：{}",ids);
        int result = departmentinfoService.updateIsDeletefromDepartmentinfoTable(ids);
        return ResultBean.InsertSuccessResult(result);
    }
}
